//
// Created by 原帅 on 2022/10/7.
//

#ifndef R_RLOG_H
#define R_RLOG_H

#include "RLogRecorder.h"
#include "iostream"
#include "vector"
#define RLOG_STACK_BUFF_MAX_SIZE 0x10000

#define RLogErr(fmt,args...) do {RLog::RecorderLog(RLogRecorder::ERROR," %s:%d:%s:" fmt,__FILE__,__LINE__,__func__,##args);}while(0);
#define RLogDbg(fmt,args...) do {RLog::RecorderLog(RLogRecorder::DEBUG," %s:%d:%s:" fmt,__FILE__,__LINE__,__func__,##args);}while(0);


class RLog {
private:
    static RLog& Inst() {
        static RLog rLog;
        return rLog;
    }

    RLogRecorder rLogRecorder;

    bool enableSTDOUT = false;
    bool disbaleLogFile = false;
    std::vector<RLogRecorder::RLOGLEVEL> vecFilterLevels;

public:
    /**
     * 是否开启标准输出打印
     * @return true or false
     */
    static bool IsEnableStdout();

    /**
     * 设置是否开启标准输出打印
     * @param enableStdout : true or false
     */
    static void SetEnableStdout(bool enableStdout);

    /**
     * 是否关闭log文件记录
     * @return true =关闭 or false=开启
     */
    static bool IsDisbaleLogFile();

    /**
     * 设置是否关闭log文件记录
     * @param disbaleLogFile : true = 关闭 or false = 开启
     */
    static void SetDisbaleLogFile(bool disbaleLogFile);

    /**
     * 记录一条log日志
     * @param rloglevel 记录的等级
     * @param format 记录的格式输出
     * @param ... 格式参数
     */
    static void RecorderLog(RLogRecorder::RLOGLEVEL rloglevel,const char* format,...);

    /**
     * Log 等级过滤器
     * @param rloglevel 要过滤掉的等级
     * @return RLog的单例
     */
    static RLog& AddLogLevelFilter(RLogRecorder::RLOGLEVEL rloglevel);

private:
    static void RecorderLog(RLogRecorder::RLOGLEVEL rloglevel,const char* format,va_list args);

    void recorderlog(RLogRecorder::RLOGLEVEL rloglevel,std::string log);
};


#endif //R_RLOG_H
